<h1 id="titre">Gestion des citations</h1>
<?php
if (isset($_POST['modifier'])) 
{
	$req = $bdd->prepare('UPDATE citations SET citation=:citation, auteur=:auteur WHERE id=:id');
	$req->execute(array(
		'citation' => stripslashes($_POST['citation']),
		'auteur' => stripslashes($_POST['auteur']),
		'id' => $_POST['id']
	));
	header('Location: index.php?page=admin_citations'); 
}
elseif (isset($_POST['effacer'])) 
{
	$req = $bdd->prepare('DELETE FROM citations WHERE id=:id');
	$req->execute(array('id' => $_POST['id']));
	header('Location: index.php?page=admin_citations'); 
}
elseif (isset($_POST['ajouter'])) 
{
	$req = $bdd->prepare('INSERT INTO citations (citation, auteur) VALUES (:citation, :auteur)');
	$req->execute(array(
		'citation' => stripslashes($_POST['citation']),
		'auteur' => stripslashes($_POST['auteur'])
	));
	header('Location: index.php?page=admin_citations'); 
}
?>
<table border="0" width="100%">
<tr><th>Citations</th><th>Auteur</th><th></th></tr>
<tr><td colspan="3"><hr /></td></tr>
<form method="post" action="index.php?page=admin_citations">
	<tr>
	<td><input type="text" name="citation" maxlength="250" size="40"></td>
	<td><input type="text" name="auteur" value="" maxlength="250" size="15"></td>
	<td width="25%"><input type="submit" value="Ajouter cette catégorie" name="ajouter" class="bouton" /></td>
	</tr>
</form>
<tr><td colspan="3"><hr /></td></tr>
<?php
$req = $bdd->query('SELECT * FROM citations ORDER BY auteur');
while ($donnees = $req->fetch())
{
	?>
	<form method="post" action="index.php?page=admin_citations">
		<tr>
		<td><input type="text" name="citation" value="<?php echo stripslashes($donnees['citation']); ?>" maxlength="250" size="40"></td>
		<td><input type="text" name="auteur" value="<?php echo stripslashes($donnees['auteur']); ?>" maxlength="250" size="15"></td>
		<td><input type="hidden" name="id" value="<?php echo $donnees['id']; ?>" />
		<input type="submit" value="Modifier" name="modifier" class="bouton" />
		<input type="submit" value="Effacer" name="effacer" class="bouton" /></td>
		</tr>
	</form>
	<?php
}
$req->closeCursor();
?>
</table>